/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package specifications;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.nodes.Tag;

/**
 *
 * @author Jason
 */
public class TypicalTasks extends Parameter implements YamlObject<TypicalTasks> {
    public static final Tag TAG = new Tag("!TypicalTasks");
    private ArrayList<Directive> preparation;
    private String initialTranslation;
    private LinkedHashMap<String, ArrayList<Directive>> qa;
    
    public static final String SELF_CHECKING = "self-checking";
    public static final String REVISION = "revision";
    public static final String REVIEW = "review";
    public static final String FINAL_FORMATTING = "final-formatting";
    public static final String PROOFREADING = "proofreading";
    
    public TypicalTasks(){
        LinkedHashMap<String, ArrayList<Directive>> temp = new LinkedHashMap<String, ArrayList<Directive>>(5);
        temp.put(SELF_CHECKING, new ArrayList<Directive>());
        temp.put(REVISION, new ArrayList<Directive>());
        temp.put(REVIEW, new ArrayList<Directive>());
        temp.put(FINAL_FORMATTING, new ArrayList<Directive>());
        temp.put(PROOFREADING, new ArrayList<Directive>());
        qa = temp;
    }
    
    public TypicalTasks(ArrayList<Directive> preparation,
                        String initialTranslation,
                        LinkedHashMap<String, ArrayList<Directive>> qa){
        setPriority(30); //default priority
        this.preparation = preparation;
        this.initialTranslation = initialTranslation;
        this.qa = qa;
    }
    
    private ArrayList<Directive> getSelfChecking(){
        return qa.get(SELF_CHECKING);
    }
    
    private void setSelfChecking(ArrayList<Directive> list){
        qa.put(SELF_CHECKING, list);
    }
    
    private ArrayList<Directive> getRevision(){
        return qa.get(REVISION);
    }
    
    private void setRevision(ArrayList<Directive> list){
        qa.put(REVISION, list);
    }
    
    private ArrayList<Directive> getReview(){
        return qa.get(REVIEW);
    }
    
    private void setReview(ArrayList<Directive> list){
        qa.put(REVIEW, list);
    }
    
    private ArrayList<Directive> getFinalFormatting(){
        return qa.get(FINAL_FORMATTING);
    }
    
    private void setFinalFormatting(ArrayList<Directive> list){
        qa.put(FINAL_FORMATTING, list);
    }
    
    private ArrayList<Directive> getProofreading(){
        return qa.get(FINAL_FORMATTING);
    }
    
    private void setProofreading(ArrayList<Directive> list){
        qa.put(FINAL_FORMATTING, list);
    }
    @Override
    public ArrayList<Directive> getDirectives() {
        ArrayList<Directive> list = new ArrayList<Directive>();
        list.addAll(getProofreading()); //The order is reversed due to appends
        list.addAll(getFinalFormatting());
        list.addAll(getReview());
        list.addAll(getRevision());
        list.addAll(getSelfChecking());
        list.addAll(preparation);
        return list;
    }

    @Override
    public void dump(String filename) throws IOException {
        Yaml yaml = new Yaml(CONSTRUCTOR, REPRESENTER);
        FileWriter writer = new FileWriter(filename);
        writer.write(yaml.dumpAs(this, TAG, DumperOptions.FlowStyle.BLOCK));
        writer.close();
    }

    @Override
    public TypicalTasks load(String filename) throws IOException {
        Yaml yaml = new Yaml(CONSTRUCTOR, REPRESENTER);
        FileReader reader = new FileReader(filename);
        TypicalTasks param = yaml.loadAs(reader, TypicalTasks.class);
        reader.close();
        return param;
    }


    /**
     * @return the preparation
     */
    public ArrayList<Directive> getPreparation() {
        return preparation;
    }

    /**
     * @param preparation the preparation to set
     */
    public void setPreparation(ArrayList<Directive> preparation) {
        this.preparation = preparation;
    }

    /**
     * @return the initialTranslation
     */
    public String getInitialTranslation() {
        return initialTranslation;
    }

    /**
     * @param initialTranslation the initialTranslation to set
     */
    public void setInitialTranslation(String initialTranslation) {
        this.initialTranslation = initialTranslation;
    }

    /**
     * @return the qa
     */
    public LinkedHashMap<String, ArrayList<Directive>> getQa() {
        return qa;
    }

    /**
     * @param qa the qa to set
     */
    public void setQa(LinkedHashMap<String, ArrayList<Directive>> qa) {
        this.qa = qa;
    }
    
}
